package com.ruowei.modules.foodOrder.repository;

import com.ruowei.modules.foodOrder.domain.CourierChangeLog;
import com.ruowei.modules.foodOrder.domain.MerchantChangeLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;

import java.time.Instant;
import java.util.Optional;

@Repository
public interface MerchantChangeLogRepository extends JpaRepository<MerchantChangeLog, Long>, QuerydslPredicateExecutor<MerchantChangeLog> {

    @Query(nativeQuery = true, value = "select * from (select * from merchant_change_log where merchant_code = ?1 and update_time < ?2 order by update_time desc) as log limit 1")
    Optional<MerchantChangeLog> getMerchantChange(String merchantCode, Instant updateTime);
}
